<?php
class accountclass extends control
{
    public function __construct()
    {
        parent::__construct();
        $this->app->loadLang('index');
    }
    public function index($recTotal = 0, $recPerPage = 20, $pageID = 0)
    {
        $this->app->loadClass('pager');
        $pager = new pager($recTotal, $recPerPage, $pageID);
        $this->view->accountClass = $this->accountclass->getList($pager);
        $this->view->pager    = $pager;
        $this->display();
    }
    /**
     * Create an article.
     *
     * @access public
     * @return void
     */
    public function create()
    {
        if(!empty($_POST)) {
            $this->accountclass->create(); // 创建校区，如果传入了pid，那么创建子校区
            if(dao::isError()) die(js::error(dao::getError()) . js::locate('back'));
            die(js::locate(inlink('index')));
        }
        $this->display();
    }

    /**
     * Update an article.
     *
     * @param  int    $id
     * @access public
     * @return void
     */
    public function edit($type)
    {
        if(!empty($_POST)) {
            $this->accountclass->update($type);
            $this->locate(inlink('index'));
        }
        else {
            $this->display();
        }
    }
    public function view($id)
    {
        $this->view->campus = $this->accountclass->getByID($id);
        $this->display();
    }

    /**
     * Delete an campus.
     *
     * @param  int    $id
     * @access public
     * @return void
     */
    public function delete($id)
    {
        // 校区内有学生，不能删除校区
        if($this->campus->delete($id) == false){
            echo "<script>alert('校区内有学生，不能删除！！');history.back();</script>";
            exit;
        }
        $this->locate(inlink('index'));
    }
    public function charge($studentId)
    {
        if(!empty($_POST)) {
            $this->student->charge();
            $this->locate(inlink('index'));
        }
        else {
            $this->student->getaccount($studentId);
            $this->view->account = $this->student->getaccount($studentId);
            $this->display();
        }
    }
}